﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace SalaryQuery
{
    public class CtreateObject
    {
        public static List<int> GetColorRowIndex(Dictionary<string, string>[] _dataDicts)
        {
            List<int> list = new List<int>();
            for (int i = 0; i < _dataDicts.Length; i++)
            {
                foreach (KeyValuePair<string, string> pair in _dataDicts[i])
                {
                    if ((pair.Value.Contains("总计") || pair.Value.Contains("小计")) || (pair.Value.Contains("合计") || pair.Value.Contains("汇总")))
                    {
                        list.Add(i);
                        break;
                    }
                }
            }
            return list;
        }

        public static object[] GetObjects(Dictionary<string, string>[] _dataDicts)
        {
            if ((_dataDicts == null) || (_dataDicts.Length == 0))
            {
                return null;
            }
            List<object> list = new List<object>();
            DynamicTypeBuilder builder = new DynamicTypeBuilder("customClass");
            foreach (KeyValuePair<string, string> pair in _dataDicts[0])
            {
                builder.AppendPublicProperty(pair.Key, typeof(string));
            }
            for (int i = 0; i < _dataDicts.Length; i++)
            {
                object obj2 = Activator.CreateInstance(builder.CreateDynamicType());
                foreach (KeyValuePair<string, string> pair2 in _dataDicts[i])
                {
                    PropertyInfo property = obj2.GetType().GetProperty(pair2.Key);
                    if ((property != null) && property.CanWrite)
                    {
                        property.SetValue(obj2, pair2.Value, null);
                    }
                }
                list.Add(obj2);
            }
            return list.ToArray();
        }
    }
}

